﻿//
// Created by work on 24-6-6.
//

#include "CRtModelYcInfo.h"

std::map<CRtModelYcInfo::EModelYcCol, QString> CRtModelYcInfo::rtModelYcColToStringMap = {
    {CRtModelYcInfo::EBase, "base"},
    {CRtModelYcInfo::ECoef, "coef"},
    {CRtModelYcInfo::EEn_alarm, "en_alarm"},
    {CRtModelYcInfo::EAlarm_up_limit, "alarm_up_limit"},
    {CRtModelYcInfo::EAlarm_down_limit, "alarm_down_limit"},
    {CRtModelYcInfo::EAlarm_up_limit_desc, "alarm_up_limit_desc"},
    {CRtModelYcInfo::EAlarm_down_limit_desc, "alarm_down_limit_desc"},
    {CRtModelYcInfo::EAlarm_time_count, "alarm_time_count"}
};

std::map<CRtModelYcInfo::EModelYcCol, QString> CRtModelYcInfo::ycColFieldsNameMap = {
    {CRtModelYcInfo::EBase, "基数"},
    {CRtModelYcInfo::ECoef, "系数"},
    {CRtModelYcInfo::EEn_alarm, "报警使能"},
    {CRtModelYcInfo::EAlarm_up_limit, "上限"},
    {CRtModelYcInfo::EAlarm_down_limit, "下限"},
    {CRtModelYcInfo::EAlarm_up_limit_desc, "上限描述"},
    {CRtModelYcInfo::EAlarm_down_limit_desc, "下限描述"},
    {CRtModelYcInfo::EAlarm_time_count, "报警持续时间"}
};

std::map<CRtModelYcInfo::EModelYcCol, CValue::EValueType> CRtModelYcInfo::rtYcDataTypeByField = {
    {CRtModelYcInfo::EBase, CValue::IOT_Float},
    {CRtModelYcInfo::ECoef, CValue::IOT_Float},
    {CRtModelYcInfo::EEn_alarm, CValue::IOT_Bool},
    {CRtModelYcInfo::EAlarm_up_limit, CValue::IOT_Float},
    {CRtModelYcInfo::EAlarm_down_limit, CValue::IOT_Float},
    {CRtModelYcInfo::EAlarm_up_limit_desc, CValue::IOT_String},
    {CRtModelYcInfo::EAlarm_down_limit_desc, CValue::IOT_String},
    {CRtModelYcInfo::EAlarm_time_count, CValue::IOT_Int}
};

CRtModelYcInfo::CRtModelYcInfo(QObject *parent) : CRtModelSigBase(YC_COL_SIZE, parent) {
    QMap<int, QString> vmap;
    vmap.insert(0, "否");
    vmap.insert(1, "是");
    m_fieldValueMap.insert(ycColFieldName(YC_ENUM::EEn_alarm), vmap);
}

QString CRtModelYcInfo::getFieldNameByCol(int col) {
    if(col < 0 || col > (YC_COL_SIZE-1))
        return "";

    if(col < SIGBASE_COL_SIZE)
        return CRtModelSigBase::getFieldNameByCol(col);

    return ycColFieldName(static_cast<EModelYcCol>(col));
}

QVariant CRtModelYcInfo::getFieldValueByFielddName(const QString &name)
{
    if(name.isEmpty())
        return QVariant();

    if(ycColFieldName(YC_ENUM::EBase) == name) {
        return base;
    } else if(ycColFieldName(YC_ENUM::ECoef) == name) {
        return coef;
    } else if(ycColFieldName(YC_ENUM::EEn_alarm) == name) {
        return en_alarm ? 1 : 0;
    } else if(ycColFieldName(YC_ENUM::EAlarm_up_limit) == name) {
        return alarm_up_limit;
    } else if(ycColFieldName(YC_ENUM::EAlarm_down_limit) == name) {
        return alarm_down_limit;
    } else if(ycColFieldName(YC_ENUM::EAlarm_up_limit_desc) == name) {
        return alarm_up_limit_desc;
    } else if(ycColFieldName(YC_ENUM::EAlarm_down_limit_desc) == name) {
        return alarm_down_limit_desc;
    } else if(ycColFieldName(YC_ENUM::EAlarm_time_count) == name) {
        return alarm_time_count;
    } else {
        return CRtModelSigBase::getFieldValueByFielddName(name);
    }
}

void CRtModelYcInfo::setFieldValueByCol(int col, const QVariant &value)
{

}

void CRtModelYcInfo::fromJson(const QJsonObject& json) {
    CRtModelSigBase::fromJson(json);
    base = json[ycFieldName(YC_ENUM::EBase)].toDouble();
    coef = json[ycFieldName(YC_ENUM::ECoef)].toDouble();
    en_alarm = json[ycFieldName(YC_ENUM::EEn_alarm)].toBool();
    alarm_up_limit = json[ycFieldName(YC_ENUM::EAlarm_up_limit)].toDouble();
    alarm_down_limit = json[ycFieldName(YC_ENUM::EAlarm_down_limit)].toDouble();
    alarm_up_limit_desc = json[ycFieldName(YC_ENUM::EAlarm_up_limit_desc)].toString();
    alarm_down_limit_desc = json[ycFieldName(YC_ENUM::EAlarm_down_limit_desc)].toString();
    alarm_time_count = json[ycFieldName(YC_ENUM::EAlarm_time_count)].toInt();
}



QJsonObject CRtModelYcInfo::toJson() {
    QJsonObject json = CRtModelSigBase::toJson();
    json[ycFieldName(YC_ENUM::EBase)] = base;
    json[ycFieldName(YC_ENUM::ECoef)] = coef;
    json[ycFieldName(YC_ENUM::EEn_alarm)] = en_alarm;
    json[ycFieldName(YC_ENUM::EAlarm_up_limit)] = alarm_up_limit;
    json[ycFieldName(YC_ENUM::EAlarm_down_limit)] = alarm_down_limit;
    json[ycFieldName(YC_ENUM::EAlarm_up_limit_desc)] = alarm_up_limit_desc;
    json[ycFieldName(YC_ENUM::EAlarm_down_limit_desc)] = alarm_down_limit_desc;
    json[ycFieldName(YC_ENUM::EAlarm_time_count)] = alarm_time_count;
    return json;
}

QSharedPointer<IModel> CRtModelYcInfo::createEmpty()
{

}

bool CRtModelYcInfo::sync(bool dir)
{

}

